package com.jy.controller;


import com.jy.common.enums.ResponseWrapper;
import com.jy.common.model.user.param.SendMessageTo;
import com.jy.common.tool.CommonTool;
import com.jy.service.ChatMessagesService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 存储聊天过程中的消息内容 前端控制器
 * </p>
 *
 * @author fzg
 * @since 2024-11-18
 */
@RestController
@RequestMapping("/chat-messages")
public class ChatMessagesController {

    private final ChatMessagesService chatMessagesService;


    public ChatMessagesController(ChatMessagesService chatMessagesService) {
        this.chatMessagesService = chatMessagesService;
    }


    /**
     * 获取聊天列表
     * @return ResponseWrapper
     */
    @GetMapping("/getAllUserMessageList")
    public ResponseWrapper getAllUserMessageList(HttpServletRequest request){
        return chatMessagesService.getAllUserMessageList(CommonTool.getUserAidByToken(request));
    }


    /**
     * 获取聊天列表
     * @return ResponseWrapper
     */
    @GetMapping("/getMessages")
    public ResponseWrapper getMessages(HttpServletRequest request, Integer userAid){
        return chatMessagesService.getMessages(CommonTool.getUserAidByToken(request),userAid);
    }



    /**
     * 发送文字消息给对方
     * @return ResponseWrapper
     */
    @PostMapping("/sendMessageTo")
    public ResponseWrapper sendMessageTo(HttpServletRequest request, @Validated @RequestBody SendMessageTo param){
        return chatMessagesService.sendMessageTo(CommonTool.getUserAidByToken(request),param);
    }


}
